package com.cbl.v.ssczs.view.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.BaseAdapter;

import com.cbl.v.ssczs.mode.util.Tools;

import java.util.List;

/**
 * Created by Administrator on 2017/3/17.
 */

public abstract class MyBaseAdapter<T> extends BaseAdapter implements View.OnClickListener,TextWatcher {
    public List<T> dataList;
    private Context context;
    private Activity activity;
    public MyBaseAdapter(){

    }

    public MyBaseAdapter(Context context){
        this.context=context;
    }


    public MyBaseAdapter(Context context, List<T> list){
        this.context=context;
        this.dataList=list;
        activity= (Activity) context;
    }


    @Override
    public int getCount() {
        return dataList == null ? 0 : dataList.size();
    }

    @Override
    public T getItem(int position) {
        return dataList == null ? null : dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public Context getContext(){
        return context;
    }

    public Activity getActivity(){
        return activity;
    }

    public void showInfo(String info){
        Tools.ShowInfo(context,info);
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {

    }


    public void startNewActivity(Class<?> cls){
        context.startActivity(new Intent(getActivity(),cls));
    }

    public void startNewActivity(Class<?> cls,String data){
        Intent intent=new Intent(getActivity(),cls);
        intent.putExtra("data",data);
        context.startActivity(intent);
    }

    public void startNewActivityWithData(Class<?> cls,String data){
        Intent intent=new Intent(getActivity(),cls);
        intent.putExtra("data",data);
        getActivity().startActivity(intent);
    }

    public void startNewActivityWithDataAndTitle(Class<?> cls,String data,String title){
        Intent intent=new Intent(getActivity(),cls);
        intent.putExtra("data",data);
        intent.putExtra("title",title);
        getActivity().startActivity(intent);
    }

    public void startNewActivityWithData(Class<?> cls,String data,int requestCode){
        Intent intent=new Intent(getActivity(),cls);
        intent.putExtra("data",data);
        getActivity().startActivityForResult(intent,requestCode);
    }


}
